loop on selected objects

Hello,

I would like to do something like
 

Module m = current
Object o
for o in selectedObjects m do {
  ...
}

 


SelectedObjects would return a Skip list of objects that are "selected" that is to say marked in pink for cut, copy, link addition, attribute edtition, etc...

Any help welcome.
Vincent.

 


SystemAdmin - Mon Mar 07 10:27:36 EST 2011

Re: loop on selected objects
SystemAdmin - Mon Mar 07 16:18:08 EST 2011

If you want to confine the loop to only the objects that have been selected in a contiguous order - that is - the user has selected the start of a selection and then used SHIFT click to select the end of a selection (DOORS changes the color of the selected range to red text) then the following will work - to prove that it works I've added an incrementing counter and print statement that confirms that the loop only works on the contiguously selected objects.
 

Module m = current
Object o, startObj, endObj
int      x = 0
 
getSelection(m,startObj, endObj)
 
if (!null startObj) {  //if range has been selected, otherwise do nothing
 
        while (!null startObj && isSelected startObj) {
                x++
                print identifier(startObj) "\n"
                startObj = next(startObj) 
                }
        print "Total Obj in selection=" x""
      }
else
        {
        print "No selection made"
        }

 


However, sometimes you want to loop through a non contiguous selected set of objects - this is a bit easier to handle because the variant of the for-do loop for objects shown below will only loop through objects that are currently visible (Display Set) including the cells of any visible DOORS tables. So if you create a filter to simulate a non contiguous selection of objects based on the filter criteria, then the loop will only loop through those objects.

 

 

 

Module m = current
Object o
 
for o in m do {.....}

 

 


Paul Miller
Melbourne, Australia

Re: loop on selected objects
llandale - Tue Mar 08 16:32:32 EST 2011

Miller's method may work, but I'm pretty set in my ways and have done it like this:

Skip    fGetSelectedObjects(Module in_mod)
{     // Return a Skip List of objects that are currently selected in the module.
        // 'Selected' means either a range of objects or the currently selected single object.
        // Return an empty skip list when there are no selected objects
        // Calling program should delete the Skip when finished.
 
        Skip    skpObjects = create()  // Return KEY and DATA both 'Object'
        if (null in_mod) return(skpObjects)
        Object  oCurr = current,
                        o
        for o in entire (in_mod) do
        {  if (isSelected(o)   or
               o == oCurr)              put(skpObjects, o, o)
        }
        return(skpObjects)
}     // end fGetSelectedObjects()
 
Skip    skpObjects = fGetSelectedObjects(current Module)
Object  o
 
for o in skpObjects do
{   // deal with the selected o
    print (identifier(o)) "\tIsSeletected\n"
}
delete(skpObjects)


Here are some possible additions you may want:
if (isDeleted(o)) continue
if (table(o) or row(o)) continue
if (cell(o)) continue

 

  • Louie

 

Re: loop on selected objects
SystemAdmin - Tue Mar 08 17:50:06 EST 2011

llandale - Tue Mar 08 16:32:32 EST 2011

Miller's method may work, but I'm pretty set in my ways and have done it like this:

Skip    fGetSelectedObjects(Module in_mod)
{     // Return a Skip List of objects that are currently selected in the module.
        // 'Selected' means either a range of objects or the currently selected single object.
        // Return an empty skip list when there are no selected objects
        // Calling program should delete the Skip when finished.
 
        Skip    skpObjects = create()  // Return KEY and DATA both 'Object'
        if (null in_mod) return(skpObjects)
        Object  oCurr = current,
                        o
        for o in entire (in_mod) do
        {  if (isSelected(o)   or
               o == oCurr)              put(skpObjects, o, o)
        }
        return(skpObjects)
}     // end fGetSelectedObjects()
 
Skip    skpObjects = fGetSelectedObjects(current Module)
Object  o
 
for o in skpObjects do
{   // deal with the selected o
    print (identifier(o)) "\tIsSeletected\n"
}
delete(skpObjects)


Here are some possible additions you may want:
if (isDeleted(o)) continue
if (table(o) or row(o)) continue
if (cell(o)) continue

 

  • Louie

 

If we were playing poker, my full house was looking pretty good, but Louie had the 4 of kind - the Skip List approach is much more robust\reliable, I would go with Louie's approach.


Paul Miller
Melbourne, Australia

Re: loop on selected objects
llandale - Wed Mar 09 15:00:36 EST 2011

SystemAdmin - Tue Mar 08 17:50:06 EST 2011
If we were playing poker, my full house was looking pretty good, but Louie had the 4 of kind - the Skip List approach is much more robust\reliable, I would go with Louie's approach.


Paul Miller
Melbourne, Australia

Actually, I like to write library functions that can be used by other programs, so there needs to be a mechanism for a function to return the list, and so a Skip list seems natural. If you don't want a library function you won't need the Skip.

Now that I think of it, however, I see that may main program will process the objects in "Object" order; not sure what to think about that. I should change the function to keep a "counter" and put the "Counter++" as the skip list "Key", they would thus be retrieved by the main in the natural order; I think the same order that your algorithm correctly finds them.

  • Louie

These are more like two-pair and trips; good hands easily trumped by better hands.

Re: loop on selected objects
SystemAdmin - Thu Mar 10 12:07:11 EST 2011

llandale - Wed Mar 09 15:00:36 EST 2011
Actually, I like to write library functions that can be used by other programs, so there needs to be a mechanism for a function to return the list, and so a Skip list seems natural. If you don't want a library function you won't need the Skip.

Now that I think of it, however, I see that may main program will process the objects in "Object" order; not sure what to think about that. I should change the function to keep a "counter" and put the "Counter++" as the skip list "Key", they would thus be retrieved by the main in the natural order; I think the same order that your algorithm correctly finds them.

  • Louie

These are more like two-pair and trips; good hands easily trumped by better hands.

Thanks all for the valuable feedback !

Vincent.

Re: loop on selected objects
ScottKirkwood - Mon Oct 19 15:37:18 EDT 2015

SystemAdmin - Thu Mar 10 12:07:11 EST 2011
Thanks all for the valuable feedback !

Vincent.

Gents,

 

The approach "appears" to be flawless, but it doesn't take into account the state of the filter.I am trying to determine the best way forward, but am a bit stumped!  Here is what I have:

void StandardizeAircraftType(string ThisOrThat)
{
 Skip fGetSelectedObjects(Module in_mod)
 {  
  Skip skpObjects = create()
  if (null in_mod)
  { 
   return(skpObjects)
  }
  Object oCurr = current, o
  for o in entire (in_mod) do
  {
   if (isSelected(o) or o == oCurr)
   {
    put(skpObjects, o, o)
   }
  }
  return(skpObjects)
 }
 
 Skip skpObjects = fGetSelectedObjects(current Module)
 Object o
 
 for o in skpObjects do
 {   // deal with the selected o
  print (identifier(o)) "\tIsSeletected\n"
  o."Thing" = ThisOrThat
 }
 delete(skpObjects)
}

StandardizeAircraftType("This")

Say I have an attribute ("Thing"), and I have three possible values, "None, This, or That". Now, say, I have half of my objects set to "None", and about a 1/3 set to "This".  If I select the "None" objects, with a corresponding string of "ZZ" in the object text (via a filter), highlight all, and run the script to change all the "None" to "That", I have this problem where it doesn't recognize the filter being on and some items being "out of view".  Therefore, all items, filter or no filter, between the selection start and selection end are being updated.  How do I further limit the issue to only see Selectable and Filtered data before editing??

 

Thanks again!

 

PS...is it just me or are there a bunch of cross symbols (  ) showing up every time I place a double space somewhere??

Re: loop on selected objects
ScottKirkwood - Mon Oct 19 15:48:17 EDT 2015

[SOLVED]

 

Nevermind, I just solved my own question:  I should be using "isFiltered".

void StandardizeAircraftType(string ThisOrThat)
{
 Skip fGetSelectedObjects(Module in_mod)
 {  
  Skip skpObjects = create()
  if (null in_mod)
  { 
   return(skpObjects)
  }
  Object oCurr = current, o
  for o in entire (in_mod) do
  {
   if ((isSelected(o) && isFiltered(o)) or o == oCurr)
   {
    put(skpObjects, o, o)
   }
  }
  return(skpObjects)
 }
 
 Skip skpObjects = fGetSelectedObjects(current Module)
 Object o
 
 for o in skpObjects do
 {   // deal with the selected o
  print (identifier(o)) "\tIsSeletected\n"
  o."Thing" = ThisOrThat
 }
 delete(skpObjects)
}

StandardizeAircraftType("This")